package com.example.ssm.controller;

import com.example.ssm.domain.User;
import com.example.ssm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/user")
    public ModelAndView findById(Integer id) {
        User user = userService.findById(id);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", user);
        // link to WEB-INF/jsp/user.jsp
        modelAndView.setViewName("user");

        return modelAndView;
    }
}
